package parameter.crop;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import dao.MyDAO;

public class Cropkind {

	/**
	 * model
	 * @author by liangtingting
	 */
	
	
	private static ArrayList crop_kind = new ArrayList() ;
	private int id;
	Cropkind(){
		
	}
	
	
	public int getId(String sk) {
		int id = 0;
		String sql = "select id from crop_kind where name='"+sk+"';";
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			conn = MyDAO.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			stmt = conn.createStatement();
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		try {
			rs = stmt.executeQuery(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			if(rs.next()) {
				this.id=rs.getInt("id");	
				id=rs.getInt("id");
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public static ArrayList getCrop_kind() throws SQLException {
		crop_kind = new ArrayList() ;
		String sql = "select * from crop_kind;";
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			conn = MyDAO.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			stmt = conn.createStatement();
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		try {
			rs = stmt.executeQuery(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			while(rs.next()) {
				crop_kind.add(rs.getString("name"));	
				
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}
		rs.close();
		stmt.close();
		conn.close();
		return crop_kind;
	}
	public void setSoil_kind(ArrayList crop_kind) {
		this.crop_kind = crop_kind;
	}
	
		
}

